import UsersApi from "../../api/users.js";
import Base from '../../pages/base.js';
// import Reg from '../users/reg.js';
export default class extends Base {
    // 登录
    async login() {
        let username = this.usernameIpt.val();
        let password = this.passwordIpt.val();
        console.log(username, password);
        const data = await UsersApi.login({
            username,
            password,
        });
        console.log(data);
        if (data.status) {
            // this.tips.html(``);
            // $('#app').load('/src/template/info.html')
            alert(`欢迎${username}`);
            location.hash = "#/info";
        } else {
            // this.tips.html(`登陆失败`);
            console.log(data);
            alert('登录失败!');
        }
    }
    // 注册
    reg() {
        location.hash = "#/reg";
        // new Reg({ el: '#app', templateUrl: '/src/template/users/reg.html' }).init();
    }
    // 执行一些事件
    handle() {
        this.loginBtn = $('.login-btn');
        this.regBtn = $('.reg-btn');
        this.usernameIpt = $('[name=username]');
        this.passwordIpt = $('[name=password]');
        this.tips = $('.tips');
        this.loginBtn.on('click', this.login.bind(this));  // 更改 this 指向，把 this 指向改为这个 class
        this.regBtn.on('click', this.reg.bind(this));
    }
}